package cn.getech.data.development.service;

import cn.getech.data.development.dto.*;
import cn.getech.data.development.entity.*;
import cn.getech.data.development.model.dto.*;
import cn.getech.data.development.model.qo.DevOpsQO;
import cn.getech.data.development.model.vo.ProcWithWorkMenusVO;
import cn.getech.data.development.model.vo.WorkSqlVO;
import cn.getech.data.intelligence.common.utils.PageUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 作业流菜单树 服务类
 * </p>
 *
 * @author hujz
 * @since 2020-04-13
 */
public interface IWorkMenuService extends IService<WorkMenu> {

    /***
     * 新增下级目录
     * @param workMenuDto
     */
    WorkMenu addsubWorkFlowMenu(WorkMenuDto workMenuDto);

    /***
     * 删除目录
     * @param workMenuDto
     */
    void delWorkFlowMenu(WorkMenuDto workMenuDto) throws Exception;

    /***
     * 新增根目录
     * @param workMenuDto
     */
    WorkMenu addWorkFlowMenu(WorkMenuDto workMenuDto);


    /***
     * 新增根目录
     * @param workMenuDto
     */
    WorkMenu addRootWorkFlowMenu(WorkMenuDto workMenuDto);

    WorkMenu addWorkFlowMGTAndSubMenu(WorkMenuDto workMenuDto);


    /***
     * 查询到对应的工程流程的菜单树结构
     * @param procId  工程id
     * @return
     */
    List<WorkMenuDto> listWorkFlowMenues(Integer procId);

    List<WorkMenuDto> listSeeWorkFlowMenues(Integer procId);


    /***
     * 查询到对应的工程流程的菜单树结构(不包含节点)
     * @param procId  工程id
     * @return
     */
    List<WorkMenuDto> listWorkFlowMenuesNotIncludeNodes(Integer procId);

    /***
     * 重命名菜单名字
     * @param workMenuDto
     */
    void updateWorkFlowMenuName(WorkMenuDto workMenuDto);

    /***
     * 删除任务节点
     * @param workMenuDto
     */
    void delWorkFlow(WorkMenuDto workMenuDto);

    /***
     * 重命名任务节点的名字
     * @param workMenuDto
     */
    void updateWorkFlowName(WorkMenuDto workMenuDto);


    /***
     * 新增默认工作流
     * @param workMenuDto
     */
    WorkMenu addDefaultWorkFlowMenu(WorkMenuDto workMenuDto);

    /***
     * 新增任务
     * @param workMenuDto
     */
    Integer addWorkJob(WorkMenuDto workMenuDto);

    void saveStartNodeAndEndNode(Long procId, Integer jobId, Integer type);

    void saveStartJobNodeAndEndJobNode(Long procId, Integer menuDepId, Integer type);

    /***
     * 获取到这个工作流下的所有的配置过的节点
     * @param workMenuDto
     * @return
     */
    List<JobNodeInfoDto> listJobNodeList(WorkMenuDto workMenuDto);

    /***
     * 获取到这个工作流下的所有的配置过的连线
     * @param workMenuDto
     * @return
     */
    List<JobLinkDto> listJobLinkList(WorkMenuDto workMenuDto, Integer linkeType);

    void updateWorkJob(JobLinkAndJobNodeDto jobLinkAndJobNodeDto);

    Boolean isHaveSysparam(List<Map<String, Object>> jobNodeConfigs, String sql);

    List<JobInfoDto> listJobList(WorkMenuDto workMenuDto);

    void updateWorkFlow(JobLinkAndJobDto jobLinkAndJobDto, Boolean aTrue);

    List<WorkMenuDto> listWorkFlows(Integer procId);

    PageUtils getWorkFlowMenus(Map<String, Object> params);

    void copyWorkJob(WorkMenuDto workMenuDto);

    List<JobNodeConf> listWorkFlowConfig(Long id);

    void runWorkJob(Long jobMenuId);

    void stopWorkJob(Long jobMenuId,Boolean isIngron);

    void stopCurrentWorkJob(Long jobMenuId);

    void runWorkFlowJob(Long jobWorkMenuId);

    void closeWorkFlowJob(Long jobWorkMenuId);

    void openWorkFlowJob(Long jobWorkMenuId);

    /****
     * 根据任务id进行运行对应的任务
     * @param jobId 任务id
     * @return oozied 任务id
     */
    String syncRunWorkJob(Long jobId, String depOOzieId);

    WorkFlowDepDto selectWorkFlowDep(WorkMenuDto workMenuDto);

    JobInfoDto getJobInfo(WorkMenuDto workMenuDto);

    /***
     * 为以前的job生成菜单
     * @param jobInfo
     */
    WorkMenu addOldWorkFlowMenu(WorkMenu workMenu, JobInfo jobInfo);


    /***
     * 重新生成对应的workflow.xml文件（带有路由功能的）
     * @param jobId      任务id
     */
    void updateRouteWorkFlowXml(Integer jobId) throws Exception;

    List<List<Integer>> listLinkedList(List<JobLinkDto> edges, Set<Integer> nodeIds);

    void cheackProcId(Integer procId, Long userId, Boolean isMangerment, Integer createPer, String userRole,Integer isImport);

    String getJobLayOozieId(Long workMenuDepId);

    List<Integer> initJobLayStartShell();

    Map<String, List<Integer>> initJobLayStartAutoShell();

    /**
     * 获取项目和菜单列表
     */
    List<ProcWithWorkMenusVO> procWithWorkMenus(Integer type);

    /***
     * 运行当前节点
     * @param workMenuDto 需要运行的节点
     */
    void runNodeJob(WorkMenuDto workMenuDto);

    /***
     * 运行上游节点
     * @param workMenuDto 需要运行的上游节点
     */
    void runUpJob(WorkMenuDto workMenuDto);

    /***
     * 运行下游节点
     * @param workMenuDto 需要运行的下游节点
     */
    void runDownJob(WorkMenuDto workMenuDto);

    Set<Integer> listDownNodes(List<JobLink> jobLinks, Integer currentNodeId, Set<JobLink> jobLinkSet);

    Set<Integer> listUpNodes(List<JobLink> jobLinks, Integer currentNodeId, Set<JobLink> reUpLinks);

    PageUtils queryPage(DevOpsQO devOpsQO);

    List<Long> listUserIds(Long userId, Integer tenantId);

    JobCronDto getCronTypeByJobId(Integer jobId);
    JobCronDto getCronTypeByDepId(Integer depId);

    void updateShellJob(WorkMenuDto workMenuDto);

    Map<String, JSONObject> updateInitWorkflowNodeParams();

    /***
     * 生成一个虚拟的任务节点
     * @param jobNodeId
     * @return
     */
    Integer copyVirJobNode(Integer jobNodeId);

    void deleteVirJobNode(Integer jobNodeId);

    void moveVirJobNode();

    List<ProcInfo> procs(Long userId, Integer tenantId);

    Integer getProIdByMenuId(Long jobMenuId);

    List<WorkMenuDto> getProjectWorkFlowMenues();

    List<WorkMenuDto> getWorkFlowMenusByUserId(Integer procId, Long userId);

    List<WorkSqlVO> taskSqls(Integer tenantId);

    void pushWebData(Long id, JobInfoDto jobInfoDto, List<JobNodeInfoDto> retJobNodeInfoList);
}
